package stark.app.function.usersys;

import androidx.lifecycle.Observer;

import com.blankj.utilcode.util.GsonUtils;
import com.stark.usersys.lib.UserModule;
import com.stark.usersys.lib.user.bean.User;

import stark.app.R;
import stark.app.databinding.ActivityUsersysDemoBinding;
import stark.common.basic.base.BaseNoModelActivity;
import stark.common.basic.event.usersys.UserSysEventProxy;

/**
 * Author：daizhongbin on 2023/2/17
 * Email：1027154338@qq.com
 * Desc:
 */
public class UserSysDemoActivity extends BaseNoModelActivity<ActivityUsersysDemoBinding> {

    @Override
    protected int onCreate() {
        return R.layout.activity_usersys_demo;
    }

    @Override
    protected void initView() {
        mDataBinding.btnUserCenter.setOnClickListener(v -> {
            UserSysEventProxy.getInstance().goUserCenter(this);
        });
    }

    @Override
    protected void initData() {
        //监听用户登录情况及用户信息变化可用如下代码
        UserModule.userManager().getUserLiveData().observe(this, new Observer<User>() {
            @Override
            public void onChanged(User user) {
                if (user == null) {
                    //未登录
                    mDataBinding.tvUserInfo.setText("用户未登录");
                } else {
                    //已登录
                    mDataBinding.tvUserInfo.setText("用户已登录，信息如下：\n" + GsonUtils.toJson(user));
                }
            }
        });
    }

}
